<template>
  <div style="margin-top: 30px;margin-left:80px;border: 0px solid red;" >
    <el-form style="margin-left: -40px" :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <div style="width: 400px;height: 60px;top: -64px;left: 20px">
        <el-form-item label="名称：">
          <el-input v-model="ruleForm.value1" placeholder="请输入关键字" style="width: 160px;"></el-input>
        </el-form-item>
      </div>
      <div style=" width: 400px;height: 0px;position: relative;top: -64px;left: 270px">
        <el-form-item label="薪资范围：">
          <el-input v-model="ruleForm.value2" placeholder="请输入关键字" style="width: 160px;"></el-input>
        </el-form-item>
      </div>
      <div style=" width: 400px;height: 0px;position: relative;top: -64px;left: 410px">
        <el-form-item label="地点：">
          <el-input v-model="ruleForm.value3" placeholder="请输入关键字" style="width: 160px;"></el-input>
        </el-form-item>
      </div>
      <div style="width: 400px;height: 50px;position: relative;top: -64px;left: 600px">
          <el-button type="primary" icon="el-icon-search" style="position: relative;left: 0px;" @click="submitForm('ruleForm')">搜索</el-button>
      </div>
    </el-form>

    <el-table
            :data="tableData"
            border
            stripe
            style="width: 100%;position: relative;top:-30px">
      <el-table-column
              fixed
              prop="reid"
              label="ID"
              width="100">
      </el-table-column>
      <el-table-column
              prop="name"
              label="名称"
              width="100">
      </el-table-column>
      <el-table-column
              prop="requirement"
              label="需求"
              width="100">
      </el-table-column>
      <el-table-column
              prop="welfare"
              label="福利"
              width="100">
      </el-table-column>
      <el-table-column
              prop="salary"
              label="薪资范围"
              width="100">
      </el-table-column>
      <el-table-column
              prop="lowEdu"
              label="最低学历"
              width="100">
      </el-table-column>
      <el-table-column
              prop="releaseDate"
              label="发布时间"
              width="100">
      </el-table-column>
      <el-table-column
              prop="contactName"
              label="负责人姓名"
              width="100">
      </el-table-column>
      <el-table-column
              prop="contactPhone"
              label="负责人电话"
              width="100">
      </el-table-column>
      <el-table-column
              prop="place"
              label="地点"
              width="100">
      </el-table-column>
      <el-table-column
              prop="number"
              label="招聘数量"
              width="100">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
                  size="mini"
                  type="danger"
                  @click="application(scope.row)">申请</el-button>

        </template>
      </el-table-column>
    </el-table>
    <el-pagination style="margin-top: 20px;float: right"
                   background
                   layout="prev, pager, next"
                   :page-size="pageSize"
                   :total="total"
                   :current-page.sync="currentPage"
                   @current-change="page">
    </el-pagination>
  </div>

</template>

<script>
  export default {
    data() {
      return {
        tableData: null,
        currentPage: 1,
        pageSize: 5,
        total: null,
        key: '',
        value: '',
        resume:'',
        ruleForm: {
          value1: '',
          value2: '',
          value3: '',
          page: '',
          size: 5
        },
        rules: {
          key: [
            { required: true, message: '请选择字段', trigger: 'change' }
          ]
        }
      }
    },
    methods:{
      submitForm(formName) {
        const _this = this
        //让翻页复原
        _this.currentPage = 1
        this.$refs[formName].validate((valid) => {
          if (valid) {
            const _this = this
            _this.ruleForm.page = _this.currentPage
            axios.get('http://localhost:8182/recruitment/search',{params:_this.ruleForm}).then(function (resp) {
              _this.tableData = resp.data.data.data
              _this.total = resp.data.data.total
            })
          }
        });

      },
      page(currentPage){
        const _this = this
        if(_this.ruleForm.value == ''){
          axios.get('http://localhost:8182/recruitment/list/'+currentPage+'/'+_this.pageSize).then(function (resp) {
            _this.tableData = resp.data.data.data
            _this.total = resp.data.data.total
          })
        } else {
          _this.ruleForm.page = _this.currentPage
          axios.get('http://localhost:8182/recruitment/search',{params:_this.ruleForm}).then(function (resp) {
            _this.tableData = resp.data.data.data
            _this.total = resp.data.data.total
          })
        }

      },
      edit(row){
        this.$router.push('/studentUpdate?id='+row.id)
      },
      application(row) {
        const _this = this
        this.$confirm('确认申请【'+row.name+'】吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          axios.delete('http://localhost:8182/recruitment/application/'+row.reid+"/"+_this.resume.rid).then(function (resp) {
            if(resp.data.code==0){
              _this.$alert('【'+row.name+'】已申请', '', {
                confirmButtonText: '确定',
                callback: action => {
                  location.reload()
                }
              });
            }
          });
        });
      }
    },
    created() {
      const _this = this
      axios.get('http://localhost:8182/recruitment/list/1/'+_this.pageSize).then(function (resp) {
        _this.tableData = resp.data.data.data
        _this.total = resp.data.data.total
      })
      let resume = JSON.parse(window.localStorage.getItem('resume'))
      this.resume = resume
    }
  }
</script>